﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace DentScan2.WebApp.Tools
{
    public class Tools
    {

        static public string GenPass()
        {
            return Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
        }


        public static string XslTransform(string xml, string xsltPath)
        {
            StringReader rdr = new StringReader(xml);
            XPathDocument xPathDocument = new XPathDocument(rdr);
            XslCompiledTransform xslt = null;
            xslt = new XslCompiledTransform();
            xslt.Load(xsltPath);
            StringBuilder sb = new StringBuilder();
            TextWriter tw = new StringWriter(sb);
            xslt.Transform(xPathDocument, null, tw);
            string result = sb.ToString();
            tw.Close();
            return result;
        }

        static public string GetMd5Hash(string input)
        {
            // Create a new instance of the MD5CryptoServiceProvider object.
            MD5 md5Hasher = MD5.Create();

            // Convert the input string to a byte array and compute the hash.
            byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));

            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder sBuilder = new StringBuilder();

            // Loop through each byte of the hashed data 
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }

        public static string GetDetailNameById(string DetailKindId)
        {
            switch (DetailKindId)
            {
                case "B": return "Багажник";
                case "DK": return "Дясна колона";
                case "K": return "Капак";
                case "KAS": return "Каскет";
                case "LK": return "Лява колона";
                case "PDK": return "Преден десен калник";
                case "PDV": return "Предна дясна врата";
                case "PLK": return "Преден ляв калник";
                case "PLV": return "Предна лява врата";
                case "T": return "Покрив";
                case "ZDK": return "Заден десен калник";
                case "ZDV": return "Задна дясна врата";
                case "ZLK": return "Заден ляв калник";
                case "ZLV": return "Задна лява врата";
                default: return "ERR";
            }
        }


        public static void ClearDropDownSelection(DropDownList ddl)
        {
            ddl.Items.Clear();
            ddl.SelectedIndex = -1;
            ddl.SelectedValue = null;
            ddl.ClearSelection(); 
        }





    }
}